Skip to content

Explicitly set -std=gnu99 (via CMAKE_C_STANDARD) for linux targets when using the bundled feature. #1480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025

Conversation

Grinkers
Copy link
Contributor

@Grinkers Grinkers commented Apr 25, 2025

https://lwn.net/ml/all/aAtlfgZQyPsfBPKA@tucnak/
The C frontend now defaults to the GNU C23 dialect.

With the latest GCC, when using bundled and static-link features, gcc tries to compile with c23 which results in a build failure due to SDL2 using reserved keywords here
https://github.com/libsdl-org/SDL/blob/07d0f51fa292895443f563f0cbde4cb3802d87fa/src/joystick/hidapi/SDL_hidapi_steam.c#L40-L44

Here's the error log for cargo build --features bundled,static-link

  /home/grinkers/code/rust-sdl2/sdl2-sys/SDL/src/joystick/hidapi/SDL_hidapi_steam.c:42:5: error: cannot use keyword 'false' as enumeration constant
     42 |     false,
        |     ^~~~~
  /home/grinkers/code/rust-sdl2/sdl2-sys/SDL/src/joystick/hidapi/SDL_hidapi_steam.c:42:5: note: 'false' is a keyword with '-std=c23' onwards
  /home/grinkers/code/rust-sdl2/sdl2-sys/SDL/src/joystick/hidapi/SDL_hidapi_steam.c:44:3: error: expected ';', identifier or '(' before 'bool'
     44 | } bool;
        |   ^~~~
  /home/grinkers/code/rust-sdl2/sdl2-sys/SDL/src/joystick/hidapi/SDL_hidapi_steam.c:44:3: warning: useless type name in empty declaration
  gmake[2]: *** [CMakeFiles/SDL2-static.dir/build.make:3067: CMakeFiles/SDL2-static.dir/src/joystick/hidapi/SDL_hidapi_steam.c.o] Error 1
  gmake[2]: *** Waiting for unfinished jobs....
  gmake[1]: *** [CMakeFiles/Makefile2:159: CMakeFiles/SDL2-static.dir/all] Error 2
  gmake: *** [Makefile:136: all] Error 2

  thread 'main' panicked at /home/grinkers/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cmake-0.1.54/src/lib.rs:1119:5:

  command did not execute successfully, got: exit status: 2

  build script failed, must exit now

@Grinkers Grinkers changed the title Explicitly set -std=gnu17 (via CMAKE_C_STANDARD) for linux targets when using the bundled feature. Explicitly set -std=gnu99 (via CMAKE_C_STANDARD) for linux targets when using the bundled feature. Apr 25, 2025
@Grinkers
Copy link
Contributor Author

Original PR was -std=gnu17, but I realized this could be a very breaking change for people on old systems. I changed it to gnu99.

https://github.com/Grinkers/rust-sdl2/actions/runs/14670059227/job/41174276590
It seems to be working fine on at least CI and gcc15.

Copy link
Contributor

@jagprog5 jagprog5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cobrand @antonilol Looks good to me but I want a second opinion - please approve only if ok.

@Grinkers thanks for the clear writeup. I totally agree that the version should be set explicitly here.

@Cobrand
Copy link
Member

Cobrand commented Jun 22, 2025

Original PR was -std=gnu17, but I realized this could be a very breaking change for people on old systems. I changed it to gnu99.

Can you put this part in the comment just above the line you added? Something like "gnu17 also works but we set the standard to the oldest available just in case someone uses a very old compiler". Otherwise lgtm, nice catch.

@Grinkers
Copy link
Contributor Author

Original PR was -std=gnu17, but I realized this could be a very breaking change for people on old systems. I changed it to gnu99.

Can you put this part in the comment just above the line you added? Something like "gnu17 also works but we set the standard to the oldest available just in case someone uses a very old compiler". Otherwise lgtm, nice catch.

I don't mind adding more notes, but it's probably not needed? reserved keywords in c23 should hopefully be clear enough that it's an issue from c23 onward. I think the chance of SDL2 no longer supporting c99 is basically 0%, as it is essentially EoL. Any major development would make any comments obsolete.

@jagprog5 jagprog5 merged commit 1eafd6f into Rust-SDL2:master Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants